package xjs.base;
xJS.DOMReader = function() {
	
	var ret,
	    TOKEN = xJS.Token;
	
	//private
	function isDOMElement(el) {
		return ((el && el.tagName) ? true : false);
	}
	
	function parent(el) {
		return isDOMElement(el) ? el.parentNode : undefined;
	}
	
	function childs(el) {
		return isDOMElement(el) ? el.childNodes : undefined;
	}
	
	function hsChildNodes(el) {
		return isDOMElement(el) ? el.hasChildNodes() : undefined;
	}
	
	/**
	 * returns childs of a dom node within a static javascript array,
	 * not within a NodeList
	 */
	function childsArray(el)
	{
		if (isDOMElement(el))
		{
			var arr = null;
			
			try
			{
				// works except ie
				arr = Array.prototype.slice.call(el.childNodes, 0);
			}
			catch(ex)
			{
				// solution for ie
				arr = new Array();
				for (var i=0; i < el.childNodes.length; ++i)
				{
					arr.push(el.childNodes[i]);
				}
			}
			
			return arr;
		}
		
		return undefined;
	}
	
	function firstChild(el) {
		return isDOMElement(el) ? el.firstChild : undefined;
	}
	
	function lastChild(el) {
		return isDOMElement(el) ? el.lastChild : undefined;
	}
	
	function siblings(el)
	{
		var sibs = undefined;
		var childs = childsArray(parent(el));
		if (typeof childs !== "undefined")
		{
			sibs = new Array();
			for (var i=0; i < childs.length; ++i)
			{
				if (childs[i] !== el)
				{
					sibs.push(childs[i]);
				}
			}
		}
		
		return sibs;
	}
	
	ret = {
		
		/**
		 * 	DOM Level 1 Node Types
		 */
		ELEMENT_NODE: 1,
		ATTRIBUTE_NODE: 2,
		TEXT_NODE: 3,
		CDATA_SECTION_NODE: 4,
		ENTITY_REFERENCE_NODE: 5,
		ENTITY_NODE: 6,
		PROCESSING_INSTRUCTION_NODE: 7,
		COMMENT_NODE: 8,
		DOCUMENT_NODE: 9,
		DOCUMENT_TYPE_NODE: 10,
		DOCUMENT_FRAGMENT_NODE: 11,
		NOTATION_NODE: 12,
		
		
			
		/**
		 * 
		 */
		isDOMElement: isDOMElement,
		
		/**
		 * 
		 */
		hasClass: null,
		
		/**
		 * 
		 */
		getStyle: null,
		
		getSiblings: siblings
		
	};
	
	xJS.isDOMElement = isDOMElement;
	
	return ret;
}();

